<?php

/* кодировка в header и iconv зависит от локали сервера */

header('Content-Type: text/html; charset= cp1251');

set_include_path(
    '.'.PATH_SEPARATOR.
    'sys/config'.PATH_SEPARATOR.
    get_include_path());

include('vars.php');
include('funct.php');

if ($_GET['music'] and $_GET['tmp']) {
    $file = $_GET['music'];
    $filename = str_replace(" ", "_", $file);
    $file = base64_decode($_GET['tmp'])."/".iconv("UTF-8", "CP1251", $file);
    $filesize = filesize($file);
    if ($filesize) {
        header ("Content-Type: audio/mpeg");
        header ("Accept-Ranges: bytes");
        header ("Content-Length: ".$filesize);  
        header ("Content-Disposition: attachment; filename=".$filename);  
        readfile($file);
    }
    else {
        header("Location: http://" . $SITE . "/?action=error");
    }
}
else {
    header("Location: http://" . $SITE . "/?action=error");
}

?>
